/**
 * +----------------------------------------------------------------------
 * | @Author: codeavatar   @Year：2021
 * +----------------------------------------------------------------------
 * | @Email: codeavatar@aliyun.com
 * +----------------------------------------------------------------------
 **/
import fwlog from '@/core/fwlog.js';
const wechat = {
  //权限列表 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html
  permission: function (scope, successcallback, failcallback, completecallback){
	uni.getSetting({
      success(res){
        fwlog.debug(res);
        if (!res.authSetting[scope]){
          //未授权
          uni.authorize({
            scope: scope,
            success(res){
              fwlog.debug(res);
              //授权成功
              successcallback && successcallback();
            },
            fail(res){
              fwlog.error(res);
			  //拒绝授权
              failcallback && failcallback();
            },
            complete(res){
              fwlog.info(res);
              completecallback && completecallback();
            }
          })
        }else{
          //已授权
          successcallback && successcallback();
        }
      },
      fail(res){
        //获取权限列表失败
        fwlog.error(res);
      },
      complete(res){
        //获取权限列表完成
        fwlog.info(res);
      }
    })
  },
  //授权设置（https://uniapp.dcloud.io/api/other/authorize?id=authorize）
  authorize:function(scope,successcallback, failcallback, completecallback){
	  uni.authorize({
	    scope: scope,
	    success(res){
	      fwlog.debug(res);
	      //授权成功
	      successcallback && successcallback();
	    },
	    fail(res){
	      fwlog.error(res);
	  			  //拒绝授权
	      failcallback && failcallback();
	    },
	    complete(res){
	      fwlog.info(res);
	      completecallback && completecallback();
	    }
	  });
  },
  //打开设置(https://developers.weixin.qq.com/community/develop/doc/000cea2305cc5047af5733de751008)
  openSetting: function (successcallback, failcallback, completecallback){
	  //打开设置(真机可操作)
	  uni.openSetting({
	  	success(res){
			fwlog.debug(res);
			successcallback && successcallback();
	  	},
	  	fail(res){
			fwlog.error(res);
			failcallback && failcallback();
	  	},
	  	complete(res){
			fwlog.info(res);
			completecallback && completecallback();
	  	}
	  });
  }
}
export default wechat